<template>
    <div style="background-color:#f4f7fa;">
        <div style="height:100%">
            <el-steps :active="1" align-center style="padding-top:20px">
                <el-step title="填写报关申请"></el-step>
                <el-step title="审核报关申请"></el-step>
                <el-step title="创建报关计划"></el-step>
            </el-steps>
            <div style="position:relative;height:100%">
                <el-button type="primary" size="mini" :loading="sLoading" style="margin: 20px 0 0 30px" @click="saveAll(0)">保存</el-button>
                <el-button type="primary" size="mini" :loading="sLoading" style="margin: 20px 0 0 10px" @click="saveAll(1)">保存并提交</el-button>
                <el-button type="primary" @click="onIsShows" size="mini" style="position:absolute;top:10px;right:0px;margin: 10px 30px 0 0">返回</el-button>
                <el-card style="margin:7px 30px 10px;">
                    <div style="font-size:18px;font-weight: 700;margin-bottom: 20px;">计划信息</div>
                    <div>
                        <el-form :model="planInformationData" class="demo-form-inline" :rules="rules" ref="planInformationDataRule">
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="仓库" label-width="130px" prop="whId">
                                    <el-select v-model="planInformationData.whId" placeholder="请选择仓库" size="small" disabled style="height:40px;width:100%">
                                        <el-option label="上海" :value="36"></el-option>
                                    </el-select>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="作业类型" label-width="120px" prop="applyType">
                                    <el-select v-model="planInformationData.applyType" placeholder="请选择作业类型" size="small" style="height:40px;width:100%" @change="jobTypeSelectChange">
                                        <el-option v-for="item in applyTypeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                                    </el-select>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="货权方" label-width="120px" prop="cargoOwner">
                                    <el-input size="mini" v-model="planInformationData.cargoOwner" placeholder="请输入货权方" style="height:40px;width:100%"></el-input>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="结算客户" label-width="130px" prop="settlementCustomer">
                                    <el-input size="mini" v-model="planInformationData.settlementCustomer" placeholder="请输入结算客户" style="height:30px;width:100%"></el-input>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="提单号" label-width="120px" prop="billOfLandingNo">
                                    <el-input size="mini" v-model="planInformationData.billOfLandingNo" placeholder="请输入提单号" style="height:30px;width:100%"></el-input>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="报关状态" label-width="120px" prop="customsStatus">
                                    <el-select v-model="planInformationData.customsStatus" placeholder="请选择报关状态" size="small" style="height:40px;width:100%" clearable>
                                        <el-option v-for="item in customsStatusList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                                    </el-select>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item label="关联报关单编号" label-width="130px">
                                    <el-input size="mini" v-model="planInformationData.rltEntryNo" placeholder="请输入关联报关单编号" style="width:100%"></el-input>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%" v-if="planInformationData.applyType != 'out'">
                                <el-form-item label="到港时间" label-width="120px">
                                    <el-date-picker
                                        v-model="planInformationData.arrivalDate"
                                        type="date"
                                        placeholder="请选择到港时间"
                                        size="mini"
                                        style="height:40px;width:100%">
                                    </el-date-picker>
                                </el-form-item>
                            </div>
                            <div style="display:inline-block;width:32%">
                                <el-form-item>
                                    <el-checkbox v-if="(planInformationData.applyType != 'out')" v-model="planInformationData.authenticateFlag" style="margin-left:55px" true-label="1" false-label="0">出库密钥</el-checkbox>
                                    <el-checkbox v-if="(planInformationData.applyType != 'out')" v-model="planInformationData.separationSign" true-label="1" false-label="0">分色</el-checkbox>
                                    <el-checkbox v-if="(planInformationData.applyType == 'out')" v-model="planInformationData.separationSign" true-label="1" false-label="0" style="margin-left:55px">分色</el-checkbox>
                                    <el-checkbox v-if="(planInformationData.customsStatus != 2)" v-model="planInformationData.dclcusFlag" true-label="2" false-label="1">报关</el-checkbox>
                                </el-form-item>
                            </div>
                            <div v-if="(planInformationData.applyType == 'out')" style="display:inline-block;width:32%;position:relative;top: 0px;">
                                <el-form-item label="合同号" label-width="120px" prop="contractNo">
                                    <el-input size="mini" v-model="planInformationData.contractNo" placeholder="请输入合同号" style="height:40px;"></el-input>
                                </el-form-item>
                            </div>
                            <div v-if="(planInformationData.applyType != 'out')" style="display:inline-block;width:32%;position:relative;top: -50px;">
                                <el-form-item label="合同号" label-width="130px" prop="contractNo">
                                    <el-input size="mini" v-model="planInformationData.contractNo" placeholder="请输入合同号" style="height:40px;"></el-input>
                                </el-form-item>
                            </div>
                            <div v-if="(planInformationData.applyType != 'out')" style="display:inline-block;width:64%">
                                <el-form-item label="备注" label-width="120px">
                                    <el-input type="textarea" rows="4" size="mini" v-model="planInformationData.remark" placeholder="请输入备注" resize="none"></el-input>
                                </el-form-item>
                            </div>
                            <div v-if="(planInformationData.applyType == 'out')" style="display:inline-block;width:64%">
                                <el-form-item label="备注" label-width="130px">
                                    <el-input type="textarea" rows="4" size="mini" v-model="planInformationData.remark" placeholder="请输入备注" resize="none"></el-input>
                                </el-form-item>
                            </div>
                        </el-form>
                    </div>
                </el-card>
                <el-card style="margin:7px 30px 10px;height:50%">
                    <div style="font-size:18px;font-weight: 700;">计划商品信息</div>
                    <div style="margin-bottom: 5px">
                        <el-button type="primary" size="mini"  style="margin: 20px 0 0 10px" @click="addTbale">新增</el-button>
                        <el-button v-if="(planInformationData.applyType == 'in' || planInformationData.applyType == 'move')" :disabled="selectTableDataListLength.length == 0" type="primary" size="mini"  style="margin: 20px 0 0 10px" @click="copyAdd">复制新增</el-button>
                        <el-button type="primary" size="mini"  style="margin: 20px 0 0 10px" :disabled="selectTableDataListLength.length == 0" @click="deleteAll">批量删除</el-button>
                        <el-upload
                            class="upload-demo"
                            style="display:inline-block"
                            :action="uploadUrlOrder"
                            :show-file-list="false"
                            :on-success="uploadSuccess">
                            <el-button v-if="(planInformationData.applyType == 'in' || planInformationData.applyType == 'move')" type="primary" size="mini"  style="margin: 20px 0 0 10px">导入</el-button>
                        </el-upload>
                        <el-button v-if="(planInformationData.applyType == 'in' || planInformationData.applyType == 'move')" type="primary" size="mini"  style="margin: 20px 0 0 10px" @click="exportTemplateHandler">导出导入模板</el-button>
                    </div>
                    <el-form>
                        <el-table
                            v-if="(planInformationData.applyType == 'in' || planInformationData.applyType == 'move')"
                            :data="tableData"
                            :row-class-name="tableRowClassName"
                            max-height="calc(50vh)"
                            style="width: 95%;margin-left: 10px;"
                            height="calc(45vh - 150px)"
                            @selection-change="selectTableData">
                            <el-table-column type="selection" width="80"></el-table-column>
                            <!-- <el-table-column type="index" width="80" label="序号"></el-table-column> -->
                            <el-table-column v-for="(item,index) in columns" :key="index" :prop="item.prop" :label="item.label" :width="item.width ? item.width : ''" :render-header="(h,obj) => addRedStar(h, obj, item.isWrited)" >
                                <template slot-scope="scope">
                                    <!-- <DatePicker placeholder="请选择" transfer type="date" split-panels v-if="item.prop == 'date'" style="width:140px" v-model="scope.row[item.prop]" size="mini"></DatePicker> -->
                                    <el-input v-if="item.type == 'input' && item.prop != 'codeQty' && item.prop != 'codeWeight'" :disabled="item.disabled" v-model="scope.row[item.prop]" size="mini" @input="changeInput(item.prop, $event, scope.row)" @blur="changeBlur(item.prop, scope.row)"></el-input>
                                    <el-input v-if="item.type == 'input' && item.prop == 'codeQty'" :disabled="scope.row['ifCodeReading'] == false || scope.row['ifCodeReading'] == 0" v-model="scope.row[item.prop]" size="mini" @input="changeInput(item.prop, $event, scope.row)" @blur="changeBlur(item.prop, scope.row)"></el-input>
                                    <el-input v-if="item.type == 'input' && item.prop == 'codeWeight'" :disabled="scope.row['ifCodeReading'] == false || scope.row['ifCodeReading'] == 0" v-model="scope.row[item.prop]" size="mini" @input="changeInput(item.prop, $event, scope.row)" @blur="changeBlur(item.prop, scope.row)"></el-input>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'dclCurrcd')" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in tradeCurrList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'legalDclUnitcd')" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in unitList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'dclUnitcd')" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in unitList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'country')" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in countryCodeList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-date-picker v-if="item.type == 'date'" type="date" size="mini" v-model="scope.row[item.prop]" style="width: 100%;" @change="dateChange"></el-date-picker>
                                    <el-checkbox v-if="item.type == 'checkbox'" v-model="scope.row[item.prop]" true-label="1" false-label="0" @change="checkChange(scope.row)"></el-checkbox>
                                    <span v-if="item.type == ''" size="mini"> {{ scope.row[item.prop] }} </span>
                                </template>
                            </el-table-column>
                            <el-table-column
                            fixed="right"
                            label="操作"
                            width="130">
                            <template slot-scope="scope">
                                <el-button type="text" size="small" @click.native.prevent="delectTableInfo(scope.row, scope.$index)">删除</el-button>
                            </template>
                            </el-table-column>
                        </el-table>
                        <el-table
                            v-if="planInformationData.applyType == 'out'"
                            :data="tableDataOut"
                            :row-class-name="tableRowClassName"
                            max-height="calc(50vh)"
                            style="width: 95%;margin-left: 10px;"
                            height="calc(45vh - 150px)"
                            @selection-change="selectTableData">
                            <el-table-column type="selection" width="80"></el-table-column>
                            <!-- <el-table-column type="index" width="80" label="序号"></el-table-column> -->
                            <el-table-column v-for="(item,index) in columnsOut" :key="index" :prop="item.prop" :label="item.label" :width="item.width ? item.width : ''" :render-header="(h,obj) => addRedStar(h, obj, item.isWrited)" >
                                <template slot-scope="scope">
                                    <!-- <DatePicker placeholder="请选择" transfer type="date" :disabled="item.disabled" split-panels v-if="item.prop == 'date'" style="width:140px" v-model="scope.row[item.prop]"></DatePicker> -->
                                    <el-input v-if="item.type == 'input' && item.prop != 'codeQty' && item.prop != 'codeWeight'" :disabled="item.disabled" v-model="scope.row[item.prop]" size="mini" @input="changeInput(item.prop, $event, scope.row)" @blur="changeBlur(item.prop, scope.row)"></el-input>
                                    <el-input v-if="item.type == 'input' && item.prop == 'codeQty'" :disabled="scope.row['ifCodeReading'] == false || scope.row['ifCodeReading'] == 0" v-model="scope.row[item.prop]" size="mini" @input="changeInput(item.prop, $event, scope.row)" @blur="changeBlur(item.prop, scope.row)"></el-input>
                                    <el-input v-if="item.type == 'input' && item.prop == 'codeWeight'" :disabled="scope.row['ifCodeReading'] == false || scope.row['ifCodeReading'] == 0" v-model="scope.row[item.prop]" size="mini" @blur="changeBlur(item.prop, scope.row)" @input="changeInput(item.prop, $event, scope.row)"></el-input>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'dclCurrcd')" :disabled="item.disabled" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in tradeCurrList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'legalDclUnitcd')" :disabled="item.disabled" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in unitList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'dclUnitcd')" :disabled="item.disabled" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in unitList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-select v-if="(item.type == 'select' && item.prop == 'country')" :disabled="item.disabled" filterable v-model="scope.row[item.prop]" size="mini">
                                        <el-option v-for="item in countryCodeList" :key="item.id" :label="item.codeName" :value="item.code"></el-option>
                                    </el-select>
                                    <el-date-picker v-if="item.type == 'date'" type="date" v-model="scope.row[item.prop]" :disabled="item.disabled" style="width: 100%;" size="mini" @change="dateChange"></el-date-picker>
                                    <el-checkbox v-if="item.type == 'checkbox'" v-model="scope.row[item.prop]" true-label="1" false-label="0" @change="checkChange(scope.row)"></el-checkbox>
                                    <span v-if="item.type == ''" size="mini"> {{ scope.row[item.prop] }} </span>
                                </template>
                            </el-table-column>
                            <el-table-column
                            fixed="right"
                            label="操作"
                            width="130">
                            <template slot-scope="scope">
                                <el-button type="text" size="small" @click.native.prevent="delectTableInfo(scope.row, scope.$index)">删除</el-button>
                            </template>
                            </el-table-column>
                        </el-table>
                    </el-form>
                </el-card>
                <el-card style="margin:7px 30px 10px;">
                    <div style="font-size:18px;font-weight: 700;margin-bottom: 10px;">附件列表</div>
                    <el-button type="primary" size="mini"  style="margin: 20px 0 0 30px" @click="uploadHandler">上传</el-button>
                    <el-button type="primary" size="mini" :disabled="selectFile.length == 0" style="margin: 20px 0 0 10px" @click="downloadFile">下载</el-button>
                    <el-button type="primary" size="mini" :disabled="selectFile.length == 0" style="margin: 20px 0 0 10px" @click="deleteFileHandle">删除</el-button>
                    <el-table
                        :data="tableDataFileList"
                        max-height="calc(30vh)"
                        style="width: 95%;margin-left: 30px;"
                        height="calc(30vh)"
                        @selection-change="selectionChange">
                        <el-table-column type="selection" width="80"></el-table-column>
                        <!-- <el-table-column type="index" width="80" label="序号"></el-table-column> -->
                        <el-table-column v-for="(item,index) in attachmentsOfListColumn" :key="index" :prop="item.prop" :label="item.label" :width="item.width ? item.width : ''" >
                        </el-table-column>
                        <el-table-column
                        fixed="right"
                        label="操作"
                        width="100">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="lookFile(scope.row)">预览</el-button>
                        </template>
                        </el-table-column>
                    </el-table>
                </el-card>
                <Modal
                    v-model="outPlanInfoShow"
                    title="新增出库单据"
                    width="80%"
                    @on-visible-change="visibleChangeHandler"
                >
                    <div slot="footer">
                        <Button type="text" style="color: #000;" @click="outPlanInfoShow = false">取消</Button>
                        <Button type="primary" class="btn-warning" @click="goodsInformation">确定</Button>
                    </div>
                    <div style="margin-bottom:10px">
                        <p style="font-weight: 700; font-size: 14px;">备选货物</p>
                        <el-table
                            height="280"
                            style="width: 100%;font-size:12px"
                            :header-cell-style="{'font-weight': 300,'color': '#111',background:'rgb(242,245,249)',padding: '3px'}"
                            :data="searchInfo"
                            v-loading="this.searchInfoLoading">
                            <el-table-column
                                type="index"
                                label="序号"
                                align="center"
                                width="60">
                            </el-table-column>
                            <el-table-column
                                v-for="item in AddColumns"
                                :key="item.prop"
                                :prop="item.prop"
                                :width="item.width"
                                :label="item.label"
                                align="center"
                                :fixed="item.fixed">
                                <el-table-column :width="item.width" v-if="item.type" :prop="item.prop" align="center" :formatter="item.formatter">
                                    <template slot="header">
                                        <Input
                                            v-if="item.prop === 'batchAttr07'"
                                            v-model="searchTableData['batchAttr07']"
                                            placeholder="输入关键字搜索"
                                            @on-enter="getStockListByOwnerCodeList"/>
                                        <Input
                                            v-if="item.prop === 'matName'"
                                            v-model="searchTableData['matName']"
                                            placeholder="输入关键字搜索"
                                            @on-enter="getStockListByOwnerCodeList"/>
                                        <Input
                                            v-if="item.prop === 'country'"
                                            v-model="searchTableData['country']"
                                            placeholder="输入关键字搜索"
                                            @on-enter="getStockListByOwnerCodeList"/>
                                        <Input
                                            v-if="item.prop === 'factoryCode'"
                                            v-model="searchTableData['factoryCode']"
                                            placeholder="输入关键字搜索"
                                            @on-enter="getStockListByOwnerCodeList"/>
                                        <Input
                                            v-if="item.prop === 'batchAttr08'"
                                            v-model="searchTableData['batchAttr08']"
                                            placeholder="输入关键字搜索"
                                            @on-enter="getStockListByOwnerCodeList"/>
                                        <Input
                                            v-if="item.prop === 'wmsBatchNum'"
                                            v-model="searchTableData['wmsBatchNum']"
                                            placeholder="输入关键字搜索"
                                            @on-enter="getStockListByOwnerCodeList"/>
                                        <el-select clearable v-model="searchTableData['settlementCustomerName']" value=""  size="mini"  placeholder="" v-if="item.prop === 'settlementCustomerName'" @change="getStockListByOwnerCodeList" filterable>
                                            <el-option
                                                v-for="item in allOwner"
                                                :key="item.id"
                                                :label="item.settlementCustomerName"
                                                :value="item.settlementCustomer">
                                            </el-option>
                                        </el-select>
                                        <DatePicker placeholder="请选择" transfer type="daterange" split-panels v-if="item.prop == 'dateInto'" style="width:140px" v-model="searchTableData['dateInto']" @on-change="getStockListByOwnerCodeList"></DatePicker>
                                        <DatePicker placeholder="请选择" transfer type="daterange" split-panels v-if="item.prop == 'dateGen'" style="width:140px" v-model="searchTableData['dateGen']" @on-change="getStockListByOwnerCodeList"></DatePicker>
                                        <DatePicker placeholder="请选择" transfer type="daterange" split-panels v-if="item.prop == 'dateExpire'" style="width:140px" v-model="searchTableData['dateExpire']" @on-change="getStockListByOwnerCodeList"></DatePicker>
                                        <Input placeholder="输入关键字搜索" clearable v-model="searchTableData['matTypCode']"  size="mini" v-if="item.prop === 'matTypName'" @on-enter="getStockListByOwnerCodeList"></Input>
                                        <el-select  clearable v-model="searchTableData['whName']"  size="mini"  placeholder="" v-if="item.prop === 'whName'" @change="getStockListByOwnerCodeList" :popper-append-to-body="false">
                                            <el-option
                                                v-for="item in whList"
                                                :key="item.id"
                                                :label="item.label"
                                                :value="item.value">
                                            </el-option>
                                        </el-select>
                                        <el-select clearable v-model="searchTableData['mscAuthentication']"  size="mini"  placeholder="" v-if="item.prop === 'mscAuthentication'" @change="getStockListByOwnerCodeList" :popper-append-to-body="false">
                                            <el-option
                                                v-for="item in mscAuthenticationList"
                                                :key="item.id"
                                                :label="item.label"
                                                :value="item.value">
                                            </el-option>
                                        </el-select>
                                        <el-select clearable v-model="searchTableData['stgTypText']"  size="mini"  placeholder="" v-if="item.prop === 'stgTypText'" @change="getStockListByOwnerCodeList" :popper-append-to-body="false">
                                            <el-option
                                                v-for="item in allStgData"
                                                :key="item.id"
                                                :label="item.stgTypText"
                                                :value="item.stgTypCode">
                                            </el-option>
                                        </el-select>
                                        <el-select clearable v-model="searchTableData['goodsBondedProperty']"  size="mini"  placeholder="" v-if="item.prop === 'goodsBondedProperty'" @change="getStockListByOwnerCodeList" :popper-append-to-body="false">
                                            <el-option
                                                v-for="item in goodsBondedPropertyList"
                                                :key="item.id"
                                                :label="item.label"
                                                :value="item.value">
                                            </el-option>
                                        </el-select>
                                        <el-select clearable v-model="searchTableData['supervisionStatus']"  size="mini"  placeholder="" v-if="item.prop === 'supervisionStatus'" @change="getStockListByOwnerCodeList" :popper-append-to-body="false">
                                            <el-option
                                                v-for="item in supervisionStatusList"
                                                :key="item.id"
                                                :label="item.label"
                                                :value="item.value">
                                            </el-option>
                                        </el-select>
                                        <el-select clearable v-model="searchTableData['productStatus']"  size="mini"  placeholder="" v-if="item.prop === 'productStatus'" @change="getStockListByOwnerCodeList" :popper-append-to-body="false">
                                            <el-option
                                                v-for="item in productStatusSelectList"
                                                :key="item.id"
                                                :label="item.label"
                                                :value="item.value">
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                            </el-table-column>
<!--                            <el-table-column label="可申报件数" fixed="right" prop="avaliableApplyQty" align="center" width="100"></el-table-column>-->
                            <el-table-column label="可出库数量" fixed="right" prop="availableQty" align="center" width="100">
                            </el-table-column>
                            <el-table-column label="操作" fixed="right" width="100" align="center">
                                <template slot-scope="scope">
                                    <el-button
                                        v-if="scope.row['availableQty'] > 0"
                                        size="mini" type="text"
                                        @click.native.prevent="addHandler(scope.$index, scope.row)"><span style="color:#5c68ee">添加</span></el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <Page style="margin-top:10px" :total="total" size="small" show-elevator show-sizer @on-change="Pagechange" @on-page-size-change="pageSizeChange" :page-size="this.pageSize" :current="this.page"></Page>
                    </div>
                    <div>
                        <p style="font-weight: 700; font-size: 14px;">已选货物</p>
                        <el-table
                            :data="selectInfo"
                            height="240"
                            style="width: 100%;font-size:12px"
                            :header-cell-style="{'font-weight': 300,'color': '#111',background:'rgb(242,245,249)',padding: '5px'}"
                        >
                            <el-table-column
                                type="index"
                                label="序号"
                                width="60">
                            </el-table-column>
                            <el-table-column v-for="item in selectColumns"
                                            :key="item.prop"
                                            :prop="item.prop"
                                            :width="item.width"
                                            :label="item.label"
                                            :formatter="item.formatter"
                                            align="center"
                            >
                            </el-table-column>
                            <el-table-column label="出库数量" fixed="right" prop="orderQty" width="120" align="center">
                                <template  slot-scope="scope">
                                  <Input v-model="scope.row['orderQty']"/>
<!--                                    <span> {{scope.row['totalQty']}} </span>-->
                                </template>
                            </el-table-column>
                            <el-table-column  fixed="right"  width="100"  label="操作" align="center">
                                <template  slot-scope="scope">
                                    <el-button type="text" size="mini" @click.native.prevent="selectInfoDelete(scope.$index, scope.row)"><span style="color:#5c68ee">删除</span></el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </Modal>
                <Modal
                    v-model="showUploadInfo"
                    title="附件列表"
                    width="60%"
                    height="60%"
                    @on-ok="fileListHandler"
                    :scrollable="true">
                    <div style="width:100%;">
                        <el-row>
                            <el-col :span="12">
                                <el-form :model="uploadInfo" class="demo-form-inline">
                                    <span>
                                        <div style="font-size: 16px;padding-bottom: 10px;">备注：</div>
                                        <el-form-item style="width:90%">
                                            <el-input type="textarea" resize="none" rows="7" v-model="uploadInfo.remark" placeholder="请填写备注" size="small" style="width:100%"></el-input>
                                        </el-form-item>
                                    </span>
                                </el-form>
                            </el-col>
                            <el-col :span="12">
                                <span>
                                    <el-upload
                                        multiple
                                        drag
                                        class="upload-demo"
                                        ref="uploadRef"
                                        :action = actionUrl
                                        :on-success="uploadSuccessFile"
                                        :on-error="uploadErrorFile">
                                        <i class="el-icon-upload"></i>
                                        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                                    </el-upload>
                                </span>
                            </el-col>
                        </el-row>
                    </div>
                </Modal>
                <PdfViewModal ref="pdfViewModal"></PdfViewModal>
            </div>
        </div>
    </div>
</template>

<script>
import { testContainerNumber } from '@/api/planInfo.js'
import { getByCodeTableTypeList, receivePushApplyInfoHandler, getStockListByOwnerCode, updatePushApplyInfoHandler, selectByCustomerType, getGoodsInfo, checkIfExistVirtualStock,
            getFileList, saveFileList, deleteFile, customerDownload, exportTemplate, importTemplate } from '@/api/bondedWarehous'
import { getOwnerCodeListByStock } from '@/api/planInfo.js'
import _ from 'lodash'
import moment from 'moment';
import PdfViewModal from '@/components/pdfViewModal/pdfViewModal';
import fileDownload from 'js-file-download';
import internal from 'stream';

export default {
    name: 'bondedWarehousingInfo',
    components: {
        PdfViewModal
    },
    data() {
        return {
            rules: {
                whId: [
                    { required: true, message: '请选择仓库', trigger: 'change' },
                ],
                applyType: [
                    { required: true, message: '请选择作业类型', trigger: 'change' },
                ],
                settlementCustomer: [
                    { required: true, message: '请输入货权方', trigger: 'blur' },
                ],
                cargoOwner: [
                    { required: true, message: '请输入结算客户', trigger: 'blur' },
                ],
                billOfLandingNo: [
                    { required: true, message: '请输入提单号', trigger: 'blur' },
                ],
                customsStatus: [
                    { required: true, message: '请选择报关状态', trigger: 'change' },
                ],
                rltEntryNo: [
                    { required: true, message: '请输入关联报关单编号', trigger: 'blur' },
                ],
                arrivalDate: [
                    { type: 'date', required: true, message: '请选择到港时间', trigger: 'change' },
                ],
                contractNo: [
                    { required: true, message: '请输入合同号', trigger: 'blur' },
                ],
                remark: [
                    { required: true, message: '请输入备注', trigger: 'blur' },
                ],
            },
            planInformationDataRule: {
                whId: '',
                applyType: '',
                settlementCustomer: '',
                cargoOwner: '',
                billOfLandingNo: '',
                customsStatus: '',
                rltEntryNo: '',
                arrivalDate: '',
                authenticateFlag: '',
                separationSign: '',
                dclcusFlag: '',
                contractNo: '',
                remark: '',
                settlementCustomerCode: '',
                cargoOwnerCode: ''
            },
            sLoading: false,
            // 品类
            categoryList: [],
            allOwner: [],
            total: 1,
            pageSize: 10,
            page: 1,
            // 计划信息数据
            planInformationData: {
                whId: 36,
                applyType: '',
                settlementCustomer: '',
                cargoOwner: '',
                billOfLandingNo: '',
                customsStatus: '',
                rltEntryNo: '',
                arrivalDate: '',
                authenticateFlag: false,
                separationSign: false,
                dclcusFlag: false,
                contractNo: '',
                remark: '',
                settlementCustomerCode: '',
                cargoOwnerCode: ''
            },
            searchTableData: {
                whName: '',
                filterValue: '',
                stgTypCode: '',
                batchAttr07: '',
                matName: '',
                matTypCode: '',
                country: '',
                mscAuthentication: '',
                goodsBondedProperty: '',
                supervisionStatus: '',
                wmsBatchNum: '',
                productStatus: '',
                dateGen: '',
                dateExpire: '',
                dateInfo: ''
            },
            // 表格内容
            tableData: [],
            tableDataOut: [],
            tableDataFileList: [],
            searchInfo: [],
            selectInfo: [],
            // 出库新增弹框
            outPlanInfoShow: false,
            goodsBondedPropertyList: [
                {label: '一般贸易', value: 1},
                {label: '保税', value: 2}
            ],
            supervisionStatusList: [
                {label: '已质押', value: 1},
                {label: '未质押', value: 0}
            ],
            productStatusSelectList: [
                {label: '正品', value: 1},
                {label: '不良品', value: 2},
                {label: '退货正品', value: 3},
                {label: '破箱', value: 4}
            ],
            // 出库新增弹框表格项
            AddColumns:[{
                prop: 'batchAttr07',
                label: '箱号',
                type: 'input',
                width: '160',
                },{
                prop: 'matName',
                label: '品名',
                width: '160',
                type: 'input'
                },{
                prop:'matTypName',
                label: '品类',
                width: '160',
                type: 'input'
                },{
                prop: 'country',
                label: '国别',
                width: '160',
                type: 'input'
                },{
                prop: 'factoryCode',
                label: '厂号',
                width: '160',
                type: 'input'
                },{
                prop: 'batchAttr08',
                label: '提单号',
                width: '160',
                type: 'input'
                },{
                prop: 'goodsBondedProperty',
                label: '保税性质',
                type: 'select',
                width: '160',
                formatter: (row) => {
                    if (row.goodsBondedProperty == 2) {
                        return '保税'
                    } else {
                        return '一般贸易'
                    }
                }
                },{
                prop: 'supervisionStatus',
                label: '质押状态',
                type: 'select',
                width: '160',
                formatter: (row) => {
                    if (row.supervisionStatus == 0) {
                    return '未质押'
                    } else {
                    return '已质押'
                    }
                }
                },{
                prop: 'dateGen',
                type: 'dateGen',
                label: '生产日期',
                width: '160'
                },{
                prop: 'dateExpire',
                type: 'dateExpire',
                label: '失效日期',
                width: '160'
                },
                {
                    prop: 'dateInto',
                    label: '入库时间',
                    width: '160',
                    type: 'date'
                },{
                prop: 'settlementCustomerName',
                type: 'settlementCustomerName',
                label: '当前结算客户',
                width: '240',
                },{
                prop: 'totalQty',
                label: '总库存件数',
                width: '160'
            }],
            selectColumns: [{
                prop: 'businessItem',
                label: '箱号',
                type: 'input',
                width: '160',
                },{
                prop: 'matName',
                label: '品名',
                width: '160',
                type: 'input'
                },{
                prop:'matTypName',
                label: '品类',
                width: '160',
                type: 'select'
                },{
                prop: 'countryName',
                label: '国别',
                width: '160',
                type: 'input'
                },{
                prop: 'factoryCode',
                label: '厂号',
                width: '160',
                type: 'input'
                },{
                prop: 'batchAttr08',
                label: '提单号',
                width: '160',
                type: 'input'
                },{
                prop: 'goodsBondedProperty',
                label: '保税性质',
                type: 'select',
                width: '160',
                formatter: (row) => {
                    if (row.goodsBondedProperty == 2) {
                    return '保税'
                    } else {
                    return '一般贸易'
                    }
                }
                },{
                prop: 'supervisionStatus',
                label: '质押状态',
                type: 'select',
                width: '160',
                formatter: (row) => {
                    if (row.supervisionStatus == 0) {
                    return '未质押'
                    } else {
                    return '已质押'
                    }
                }
                },{
                prop: 'dateGen',
                type: 'dateGen',
                label: '生产日期',
                width: '160'
                },{
                prop: 'dateExpire',
                type: 'dateExpire',
                label: '失效日期',
                width: '160'
                },
                {
                    prop: 'dateInto',
                    label: '入库时间',
                    width: '160',
                    type: 'date'
                },{
                prop: 'settlementCustomerName',
                type: 'settlementCustomerName',
                label: '当前结算客户',
                width: '240',
                },
                {
                prop: 'totalQty',
                label: '总库存件数',
                width: '130'
                }
            ],
            // 附件列表项
            attachmentsOfListColumn:[
                {
                    label: '文件名称',
                    prop: 'fileName'
                },
                {
                    label: '创建时间',
                    prop: 'createdDate'
                },
                {
                    label: '备注',
                    prop: 'remark'
                }
            ],
            // 表格项
            columns:[
                {
                    label: '报关单序号',
                    prop: 'entryGdsSeqno',
                    type: 'input',
                    width: 150
                },
                {
                    label: '集装箱号',
                    prop: 'containerNum',
                    type: 'input',
                    width: 230
                },
                {
                    label: '品名',
                    prop: 'matName',
                    type: 'input',
                    width: 200
                },
                {
                    label: '规格型号',
                    prop: 'packFormat',
                    type: 'input',
                    width: 200
                },
                {
                    label: '商品编码',
                    prop: 'hscode',
                    type: 'input',
                    width: 200
                },
                {
                    label: '原产国',
                    prop: 'country',
                    type: 'select',
                    width: 200
                },
                {
                    label: '生产日期',
                    prop: 'dateGen',
                    type: 'date',
                    width: 250
                },
                {
                    label: '件数',
                    prop: 'orderQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '申报数量',
                    prop: 'dclQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '申报计量单位',
                    prop: 'dclUnitcd',
                    type: 'select',
                    width: 200
                },
                {
                    label: '法定第一数量',
                    prop: 'legalDclQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '法定第一计量单位',
                    prop: 'legalDclUnitcd',
                    type: 'select',
                    width: 200
                },
                {
                    label: '币制',
                    prop: 'dclCurrcd',
                    type: 'select',
                    width: 200
                },
                {
                    label: '单价',
                    prop: 'dclUprcAmt',
                    type: '',
                    width: 200
                },
                {
                    label: '总价',
                    type: 'input',
                    prop: 'dclTotalAmt',
                    width: 200
                },
                {
                    label: '净重',
                    prop: 'netWt',
                    type: 'input',
                    width: 200
                },
                {
                    label: '毛重',
                    prop: 'grossWt',
                    type: 'input',
                    width: 200
                },
                {
                    label: '厂号',
                    prop: 'factoryCode',
                    type: 'input',
                    width: 200
                },
                {
                    label: '是否抄码',
                    prop: 'ifCodeReading',
                    type: 'checkbox',
                    width: 100
                },
                {
                    label: '抄码件数',
                    prop: 'codeQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '抄码重量',
                    prop: 'codeWeight',
                    type: 'input',
                    width: 200
                },
                {
                    label: '作业车号',
                    prop: 'carNo',
                    type: 'input',
                    width: 200
                },
                {
                    label: '作业司机名称',
                    prop: 'driver',
                    type: 'input',
                    width: 200
                },
                {
                    label: '司机联系方式',
                    prop: 'tel',
                    type: 'input',
                    width: 200
                }
            ],
            // 附件列表展示
            showUploadInfo: false,
            // 出库的表格项
            columnsOut:[
            {
                    label: '报关单序号',
                    prop: 'entryGdsSeqno',
                    type: 'input',
                    width: 150
                },
                {
                    label: '集装箱号',
                    prop: 'containerNum',
                    type: 'input',
                    width: 230,
                    disabled: true
                },
                {
                    label: '品名',
                    prop: 'matName',
                    type: '',
                    width: 200
                },
                {
                    label: '规格型号',
                    prop: 'packFormat',
                    type: '',
                    width: 200
                },
                {
                    label: '商品编码',
                    prop: 'hscode',
                    type: 'input',
                    width: 200
                },
                {
                    label: '原产国',
                    prop: 'countryName',
                    type: '',
                    width: 200
                },
                {
                    label: '生产日期',
                    prop: 'dateGen',
                    type: 'date',
                    disabled: true,
                    width: 250
                },
                {
                    label: '件数',
                    prop: 'orderQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '申报数量',
                    prop: 'dclQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '申报计量单位',
                    prop: 'dclUnitcd',
                    type: 'select',
                    width: 200
                },
                {
                    label: '法定第一数量',
                    prop: 'legalDclQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '法定第一计量单位',
                    prop: 'legalDclUnitcd',
                    type: 'select',
                    width: 200,
                    disabled: true
                },
                {
                    label: '币制',
                    prop: 'dclCurrcd',
                    type: 'select',
                    width: 200,
                    disabled: true
                },
                {
                    label: '单价',
                    prop: 'dclUprcAmt',
                    type: '',
                    width: 200
                },
                {
                    label: '总价',
                    prop: 'dclTotalAmt',
                    type: 'input',
                    width: 200
                },
                {
                    label: '净重',
                    prop: 'netWt',
                    type: 'input',
                    width: 200
                },
                {
                    label: '毛重',
                    prop: 'grossWt',
                    type: 'input',
                    width: 200
                },
                {
                    label: '厂号',
                    prop: 'factoryCode',
                    type: 'input',
                    width: 200,
                    disabled: true
                },
                {
                    label: '是否抄码',
                    prop: 'ifCodeReading',
                    type: 'checkbox',
                    width: 100
                },
                {
                    label: '抄码件数',
                    prop: 'codeQty',
                    type: 'input',
                    width: 200
                },
                {
                    label: '抄码重量',
                    prop: 'codeWeight',
                    type: 'input',
                    width: 200
                },
                {
                    label: '作业车号',
                    prop: 'carNo',
                    type: 'input',
                    width: 200
                },
                {
                    label: '作业司机名称',
                    prop: 'driver',
                    type: 'input',
                    width: 200
                },
                {
                    label: '司机联系方式',
                    prop: 'tel',
                    type: 'input',
                    width: 200
                }
            ],
            // 作业类型
            applyTypeList: [
                {
                    label: '入库',
                    value: 'in'
                },
                {
                    label: '人工到货',
                    value: 'move'
                },
                {
                    label: '正常出库',
                    value: 'out'
                }
            ],
            // 报关类型
            customsStatusList: [
                {
                    label: '未报关',
                    value: '1'
                },
                {
                    label: '已报关',
                    value: '2'
                }
            ],
            // 上传文件
            uploadInfo: {
                fileName: '',
                remark: ''
            },
            isShipDate: false,
            // 计量单位
            unitList: [],
            // 币制
            tradeCurrList: [],
            countryCodeList: [],
            // 表格选中项
            selectTableDataList: [],
            // 结算客户
            customerTypeList: [],
            searchOwnerCode: '',
            searchManageCompanyCode: '',
            searchInfoLoading: false,
            closeAdd: false,
            selectInfoCopy: [],
            editItem: {},
            fileList: [],
            actionUrl: '',
            selectInfoClone: {},
            selectFile: [],
            uploadUrlOrder: '',
            selectTableDataListLength: [],
            telTrue: false
        }
    },
    methods: {
        exportTemplateHandler() {
            exportTemplate(this.wmsUrl).then(({data}) => {
                fileDownload(data, '保税报关计划导入模板.xlsx');
            })
        },
        Pagechange(page) {
            this.page = page,
            this.getStockListByOwnerCodeList('', page);
        },
        pageSizeChange(pageSize) {
            this.pageSize = pageSize
            this.getStockListByOwnerCodeList('', pageSize);
        },
        selectionChange(selection) {
            this.selectFile = selection;
        },
        // 保存附件
        saveFile(id) {
            let body = []
            this.fileList.forEach(item => {
                body.push({
                    "fileName": item.fileName,
                    "fileUrl": item.fileUrl,
                    "fileStatus": "0",
                    "id": null,
                    "ids": 0,
                    "fileType": "10",
                    "businessNum": id,
                    "businessType": "",
                    "customerCode": "",
                    remark: item.remark,
                    createUser: this.$utils.getUserInfo().realName
                });
            })
            saveFileList(body, this.wmsUrl).then(({data}) => {
                if (data.returnCode == 200) {
                    let body = {
                        "pageNum": 1,
                        "pages": 1,
                        "pageSize": 50,
                        "pageOptionsList": [
                        50,
                        100,
                        200
                        ],
                        "total": 0,
                        "sortList": [],
                        "filterList": [],
                        "selectCustomerCode": "",
                        "selectOutPlanOrderNum": "",
                        "ccisPledgePlanId": this.editItem.id, //报关申请id, 货转申请id
                        "ccisSeparationPlanId": "", //分色申请id
                        "searchOrderType": ""
                    }
                    getFileList(body, this.wmsUrl).then(({data}) => {
                        if (data.returnCode == 200) {
                            this.tableDataFileList = data.returnData.pageInfo.list
                            this.tableDataFileList.forEach(item => {
                                item.createdDate = this.$utils.timestampToDate(item.createdDate);
                            });
                        }
                    })
                }
            });
        },
        getViewInfo(item) {
            this.dialogTableVisible = true
        },
        downloadFile() {
            let body = [];
            this.selectFile.forEach(item => {
                body.push({
                    id: item.id ? item.id : '',
                    customerCode: "",
                    businessNum: "", //申请id
                    businessType: "50",
                    fileName: item.fileName,
                    fileUrl: item.fileUrl,
                    remark: null,
                    createdBy: "",
                    createdDate: "",
                    lastModifiedBy: "",
                    lastModifiedTime: "",
                    deleteFlag: 0,
                    fileSource: "W",
                    businessItem: null,
                    fileType: "5", //报关计划申请，货转申请传
                    fileTypeList: null,
                    minioObjectName: null,
                    displayName: "",
                    fileTypeName: "",
                    fileSuffix: "",
                    fileSuffixEdit: "",
                    shortFileName: ""
                })
            });
            customerDownload(body[0], this.wmsUrl).then(({data}) => {
                fileDownload(data, 'EDOC' + body[0].fileName.split(',')[0].toLowerCase())
            });
        },
        addRedStar(h, { column }, required) {
            if (this.planInformationData.customsStatus == 2) {
                if (column.property == 'entryGdsSeqno' || column.property == 'containerNum' || column.property == 'matName' || column.property == 'packFormat' || column.property == 'hscode'
                    || column.property == 'country' || column.property == 'orderQty' || column.property == 'dclQty' || column.property == 'dclUnitcd' || column.property == 'legalDclQty'
                    || column.property == 'legalDclUnitcd' || column.property == 'dclCurrcd' || column.property == 'dclUprcAmt' || column.property == 'dclTotalAmt'|| column.property == 'netWt' || column.property == 'carNo'|| column.property == 'driver' || column.property == 'tel') {
                    return [
                        h('span', { style: 'color: red' }, '*'),
                        h('span', ' ' + column.label)
                    ]
                } else {
                    return [
                        h('span', { } , column.label)
                    ]
                }
            } else {
                if (column.property == 'entryGdsSeqno' || column.property == 'containerNum' || column.property == 'matName' || column.property == 'packFormat' || column.property == 'hscode'
                    || column.property == 'country' || column.property == 'orderQty' || column.property == 'dclQty' || column.property == 'dclUnitcd' || column.property == 'legalDclQty'
                    || column.property == 'legalDclUnitcd' || column.property == 'dclCurrcd' || column.property == 'dclUprcAmt' || column.property == 'dclTotalAmt' || column.property == 'netWt') {
                    return [
                        h('span', { style: 'color: red' }, '*'),
                        h('span', ' ' + column.label)
                    ]
                } else {
                    return [
                        h('span', { } , column.label)
                    ]
                }
            }
        },
        tableRowClassName({row, rowIndex}) {
            if (row.deleteFlag == true) {
                return 'warning-row'
            } else {
                return ''
            }
        },
        // 成功上传
        uploadSuccess(response, file, fileList) {
            if (response.returnCode == 200) {
                this.$Message.success('导入成功');
                response.returnData.forEach(item => {
                    item['ifCodeReading'] = false
                    item['deleteFlag'] = 0;
                    item.dclQty = (item.dclQty * 1).toFixed(3)
                    item.dclTotalAmt = ((item.dclTotalAmt * 1).toFixed(10)) * 1
                    item.dclUprcAmt = ((item.dclTotalAmt * 1) / (item.dclQty * 1)).toFixed(5)
                    this.tableData.push(_.cloneDeep(item));
                })
            } else if (response.returnCode != 200) {
                this.$alert(response.returnMsg, '提示', {
                    confirmButtonText: '确定'
                })
            }
        },
        uploadSuccessFile(response, file, fileList) {
            response.returnData['indexN'] = this.fileList.length
            this.$Message.success('上传成功');
            this.fileList.push(response.returnData);
        },
        fileListHandler() {
            this.fileList.forEach(item => {
                item['remark'] = _.cloneDeep(this.uploadInfo.remark);
                this.tableDataFileList.push({
                    fileName: item.fileName,
                    createdDate: this.$utils.timestampToDate(item.createdDate),
                    remark: _.cloneDeep(this.uploadInfo.remark),
                    fileUrl: item.fileUrl,
                    indexN: this.tableDataFileList.length
                })
            });
            this.uploadInfo.remark = '';
        },
        uploadErrorFile() {
            this.$Message.error('上传失败');
        },
        // 弹框关闭
        visibleChangeHandler(item) {
            if (item == false) {
                this.selectInfo = [];
            }
        },
        // 返回列表页面
        onIsShows() {
            this.$router.push({
                name: 'bondedWarehousing'
            });
        },
        selectInfoDelete(index, rows){
            // this.searchInfo.push(this.selectInfoClone);
            this.selectInfo.splice(index, 1)
            this.selectInfoCopy = _.cloneDeep(this.selectInfo);
            this.getStockListByOwnerCodeList();
        },
        dateChange(info) {
            info = new Date(moment(info).format('YYYY-MM-DD'))
        },
        checkChange(item) {
            if (item.ifCodeReading == 0) {
                item.codeQty = '';
                item.codeWeight = '';
            } else {
                item.codeQty = _.cloneDeep(item.orderQty);
            }
        },
        addHandler(index, rows) {
            this.selectInfoClone = _.cloneDeep(rows);
            this.searchInfo.splice(index, 1);
            this.selectInfoCopy.push(rows);
            let body = [];
            body.push({
                customsDeclarePlanNum: "",
                planItem:  "",
                wmsBatchNum: rows.wmsBatchNum
            })
            getGoodsInfo(body,this.wmsUrl).then(({data}) => {
                if (data.returnCode == 200) {
                    let wmsBatchNum = rows.wmsBatchNum
                    data.returnData[wmsBatchNum]['matName'] = rows.matName;
                    data.returnData[wmsBatchNum]['matTypName'] = rows.matTypName;
                    data.returnData[wmsBatchNum]['batchAttr08'] = rows.batchAttr08;
                    // data.returnData[wmsBatchNum]['dateGen'] = rows.dateGen;
                    data.returnData[wmsBatchNum]['dateExpire'] = rows.dateExpire;
                    data.returnData[wmsBatchNum]['dateInto'] = rows.dateInto;
                    data.returnData[wmsBatchNum]['settlementCustomerName'] = rows.settlementCustomerName;
                    data.returnData[wmsBatchNum]['totalQty'] = rows.totalQty;
                    data.returnData[wmsBatchNum]['wmsBatchNum'] = rows.wmsBatchNum;
                    data.returnData[wmsBatchNum]['orderQty'] = _.cloneDeep(rows.availableQty);
                    data.returnData[wmsBatchNum]['filterUniqueCode'] = rows.filterUniqueCode
                    data.returnData[wmsBatchNum]['matCode'] = rows.matCode;
                    data.returnData[wmsBatchNum]['moveFlag'] = rows.moveFlag;
                    data.returnData[wmsBatchNum]['goodsBondedProperty'] = rows.goodsBondedProperty;
                    data.returnData[wmsBatchNum]['supervisionStatus'] = rows.supervisionStatus;
                    data.returnData[wmsBatchNum]['hscode'] = rows.hscode
                    this.countryCodeList.forEach(c => {
                        if (c.code == data.returnData[wmsBatchNum].country) {
                            data.returnData[wmsBatchNum].country = c.code
                            data.returnData[wmsBatchNum].countryName = c.codeName
                        }
                    })
                    // data.returnData.wmsBatchNum['matName'] = data.returnData.wmsBatchNum.gdsNm;
                    this.selectInfo.push(data.returnData[wmsBatchNum])
                } else {
                    this.$Message.error(data.returnMsg);
                }
            })
            // rows['orderQty'] = rows.totalQty
            this.outQty = rows.totalQty;
        },
        // 新增数据
        addTbale() {
            if (this.planInformationData.applyType == 'in' || this.planInformationData.applyType == 'move') {
                this.tableData.push({deleteFlag: 0, indexS: this.tableData.length, ifCodeReading: 0, codeQty: '',netWt: '',grossWt: '',legalDclQty: '',dclQty: '',orderQty: ''});
            } else {
                this.selectCustomerInfoByDto();
                this.searchTableData = {
                    whName: '',
                    filterValue: '',
                    stgTypCode: '',
                    batchAttr07: '',
                    matName: '',
                    matTypCode: '',
                    country: '',
                    mscAuthentication: '',
                    goodsBondedProperty: '',
                    supervisionStatus: '',
                    wmsBatchNum: '',
                    productStatus: '',
                    dateGen: '',
                    dateExpire: '',
                    dateInfo: ''
                }
                this.outPlanInfoShow = true;
                this.page = 1;
                this.searchInfo = [];
                this.selectInfoCopy = [];
                // this.tableDataOut = this.tableDataOut.filter(item => item.deleteFlag != 1)
                if (this.tableDataOut.length > 0) {
                    this.tableDataOut.forEach(item => {
                        if (this.editItem.id) {
                            item['businessItem'] = item.containerNum
                            item['totalQty'] = (item.orderQty * 1).toFixed(0)
                            if (item.dateInto) {
                                item.dateInto = this.$utils.timestampToDate(item.dateInto)
                            }
                            if (item.dateGen) {
                                item.dateGen = this.$utils.timestampToDate(item.dateGen)
                            }
                            if (item.dateExpire) {
                                item.dateExpire = this.$utils.timestampToDate(item.dateExpire)
                            }
                        }
                    })
                    this.selectInfo =  _.cloneDeep(this.tableDataOut.filter(item => item.deleteFlag != 1));
                    this.selectInfoCopy = _.cloneDeep(this.tableDataOut.filter(item => item.deleteFlag != 1));
                }
                this.getStockListByOwnerCodeList();
            }
        },
        // 预览
        lookFile(row) {
            let suffix = row.fileName.split('.')[1].toLowerCase();
            if (suffix != 'pdf' && suffix != 'png' && suffix != 'jpg' && suffix != 'jpeg') {
                this.$message.warning('不能预览非PDF、png、jpg、jpeg格式的文件');
                return;
            }
            this.$refs.pdfViewModal.loadFile(row, this.planInformationData.whId);
        },
        deleteFileHandle() {
            this.selectFile.forEach((item, index) => {
                if (item.id) {
                    let body = {
                        "fileName": item.fileName, //附件名称
                        "fileUrl": item.fileUrl, //附件url
                        "fileStatus": "0",
                        "id": item.id, //返回的文件id 没有保存的传null
                        "ids": 0,
                        "fileType": "10"
                    }
                    deleteFile(body, this.wmsUrl).then(({data}) => {
                        if (data.returnCode == 200) {
                            // this.$Message.success('操作成功');
                            let body = {
                                "pageNum": 1,
                                "pages": 1,
                                "pageSize": 50,
                                "pageOptionsList": [
                                50,
                                100,
                                200
                                ],
                                "total": 0,
                                "sortList": [],
                                "filterList": [],
                                "selectCustomerCode": "",
                                "selectOutPlanOrderNum": "",
                                "ccisPledgePlanId": this.editItem.id, //报关申请id, 货转申请id
                                "ccisSeparationPlanId": "", //分色申请id
                                "searchOrderType": ""
                            }
                            getFileList(body, this.wmsUrl).then(({data}) => {
                                if (data.returnCode == 200) {
                                    this.tableDataFileList = data.returnData.pageInfo.list
                                    this.tableDataFileList.forEach(item => {
                                        item.createdDate = this.$utils.timestampToDate(item.createdDate);
                                    });
                                }
                            })
                        } else {
                            this.$Message.error(this.returnMsg);
                        }
                    });
                } else {
                    this.selectFile.forEach(item => {
                        this.tableDataFileList.forEach((items, index) => {
                            if (item.indexN == items.indexN) {
                                this.tableDataFileList.splice(index, 1);
                            }
                        })
                    })
                }
            })
        },
        totalQtyHandler() {
            this.selectInfo.some((selectInfoItem) =>{
            if (selectInfoItem.totalQtyNew > selectInfoItem.availableQty) {
                // this.$message.warning('出库数量不可大于可出库数量');
                this.closeAdd = false
                return true;
            } else {
                this.closeAdd = true
            }
            })
        },
        // 确定选取内容
        goodsInformation(){
            this.tableDataOut.forEach(items => {
                this.selectInfoCopy = this.selectInfoCopy.filter(item => {
                    if (items.filterUniqueCode != item.filterUniqueCode) {
                        return item;
                    }
                })
            })
            checkIfExistVirtualStock(this.selectInfoCopy, this.wmsUrl).then(({data}) => {
                if (data.returnCode == 200) {
                    // this.tableDataOut.forEach(item => {
                    //     item.deleteFlag = 1;
                    // });
                    this.totalQtyHandler();
                    this.tableDataOut = [];
                    if (this.editItem){
                        if (this.closeAdd) {
                        this.outPlanInfoShow = false
                        this.selectInfo.forEach((item) => {
                            item.ifCodeReading = 0
                            item.containerNum = item.businessItem;
                            item.packFormat = item.packName;
                            item.packFormat = item.gdsSpcfModelDesc;
                            // item.matCode = item.gdecd;
                            item.indexS = this.tableDataOut.length;
                            // item.orderQty = _.cloneDeep(item.totalQtyNew);
                            let addT = true;
                            if (this.editItem.matCodeDetailList) {
                                this.editItem.matCodeDetailList.forEach(items => {
                                    if (item.filterUniqueCode == items.filterUniqueCode) {
                                        addT = false
                                        return;
                                    }
                                })
                                if (addT) {
                                  console.log(item)
                                    item.id = '';
                                    this.tableDataOut.push(item);
                                }
                            } else {
                              console.log(item)
                                item.id = '';
                                this.tableDataOut.push(item);
                            }

                        })
                        } else {
                        this.$Message.error('出库数量不能大于可出库数量')
                        }
                    } else {
                        if (this.closeAdd) {
                            this.outPlanInfoShow = false
                            this.selectInfo.forEach((item) => {
                              console.log(item)
                                item.ifCodeReading = 0
                                item.containerNum = item.businessItem;
                                item.packFormat = item.packName;
                                item.packFormat = item.gdsSpcfModelDesc;
                                item.matCode = item.gdecd
                                this.tableDataOut.push(item);
                            })
                        } else {
                        this.$Message.error('出库数量不能大于可出库数量')
                        }
                    }
                    console.log(this.tableDataOut)
                    // this.selectInfo = [];
                } else {
                    this.$Message.error(data.returnMsg);
                }
            });
        },
        filterTime(time) {
            var date = new Date(time);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? "0" + m : m;
            var d = date.getDate();
            d = d < 10 ? "0" + d : d;
            var h = date.getHours();
            h = h < 10 ? "0" + h : h;
            var minute = date.getMinutes();
            minute = minute < 10 ? "0" + minute : minute;
            var s = date.getSeconds();
            s = s < 10 ? "0" + s : s;
            return y + "-" + m + "-" + d;
        },
        // 获取库存信息
        getStockListByOwnerCodeList(event, page) {
            this.searchInfoLoading = true;
            let body = {
                "filterList": [
                    {filterKey: "queryMove", filterValue: "1"}
                ],
                "filterName": [],
                "stkCodeList": [],
                "wmsBatchNumList": [],
                "pageNum": this.page,
                "pageSize": this.pageSize,
                "pageOptionsList": [
                    50,
                    100,
                    200
                ],
                "searchKeyOrderType": null,
                "sortList": [],
                "searchKey": "",
                "searchOwnerCode": this.searchOwnerCode, //货主
                "searchWhCode": "",
                "searchManageCompanyCode": this.searchManageCompanyCode.toString(), //运营公司
                "separationOrderNum": ""
            }
            if (this.searchTableData.batchAttr07 !== '') {
                body.filterList.push({ filterKey: 'batchAttr07', filterValue: this.searchTableData.batchAttr07})
            }
            if (this.searchTableData.settlementCustomerName) {
                body.filterList.push({ filterKey: 'searchSettlementCustomer', filterValue: this.searchTableData.settlementCustomerName})
            }
            if (this.searchTableData.dateGen && this.searchTableData.dateGen.length > 1) {
            let start
            let end
            if(this.searchTableData.dateGen[0]){
                start = this.$utils.timestampToDate(this.searchTableData.dateGen[0]);
            }
            if(this.searchTableData.dateGen[1]){
                end = this.$utils.timestampToDate(this.searchTableData.dateGen[1]);
            }
                body.filterList.push({ filterKey: 'dateGenStart', filterValue: start})
                body.filterList.push({ filterKey: 'dateGenEnd', filterValue: end})
            }
            if (this.searchTableData.dateInto&& this.searchTableData.dateInto.length > 1) {
                let start
                let end
            if(this.searchTableData.dateInto[0]){
                start = this.filterTime(this.searchTableData.dateInto[0])
            }
            if(this.searchTableData.dateInto[1]){
                end = this.filterTime(this.searchTableData.dateInto[1])
            }
                body.filterList.push({ filterKey: 'dateIntoStartDate', filterValue: start})
                body.filterList.push({ filterKey: 'dateIntoEndDate', filterValue: end})
            }
            if (this.searchTableData.dateExpire&& this.searchTableData.dateExpire.length > 1) {
                let start
                let end
            if(this.searchTableData.dateExpire[0]){
                start = this.filterTime(this.searchTableData.dateExpire[0])
            }
            if(this.searchTableData.dateExpire[1]){
                end = this.filterTime(this.searchTableData.dateExpire[1])
            }
                body.filterList.push({ filterKey: 'dateExpireStart', filterValue: start})
                body.filterList.push({ filterKey: 'dateExpireEnd', filterValue: end})
            }
            if (this.searchTableData.factoryCode) {
                body.filterList.push({ filterKey: 'factoryCode', filterValue: this.searchTableData.factoryCode})
            }
            if (this.searchTableData.batchAttr08) {
                body.filterList.push({ filterKey: 'batchAttr08', filterValue: this.searchTableData.batchAttr08})
            }
            if (this.searchTableData.whName !== '') {
                body.filterList.push({ filterKey: 'whName', filterValue: this.searchTableData.whName})
            }
            if (this.searchTableData.filterValue !== '') {
                body.filterList.push({ filterKey: 'filterValue', filterValue: this.searchTableData.filterValue})
            }
            if (this.searchTableData.stgTypCode !== '') {
                body.filterList.push({ filterKey: 'stgTypCode', filterValue: this.searchTableData.stgTypCode})
            }
            if (this.searchTableData.matName !== '') {
                body.filterList.push({ filterKey: 'matName', filterValue: this.searchTableData.matName})
            }
            if (this.searchTableData.matTypCode !== '') {
                body.filterList.push({ filterKey: 'matTypCode', filterValue: this.searchTableData.matTypCode})
            }
            if (this.searchTableData.country !== '') {
                body.filterList.push({ filterKey: 'country', filterValue: this.searchTableData.country})
            }
            if (this.searchTableData.mscAuthentication !== '') {
                body.filterList.push({ filterKey: 'mscAuthentication', filterValue: this.searchTableData.mscAuthentication})
            }
            if (this.searchTableData.goodsBondedProperty !== '') {
                body.filterList.push({ filterKey: 'goodsBondedProperty', filterValue: this.searchTableData.goodsBondedProperty})
            }
            if (this.searchTableData.supervisionStatus !== '') {
                body.filterList.push({ filterKey: 'supervisionStatus', filterValue: this.searchTableData.supervisionStatus})
            }
            if (this.searchTableData.wmsBatchNum !== '') {
                body.filterList.push({ filterKey: 'wmsBatchNum', filterValue: this.searchTableData.wmsBatchNum})
            }
            if (this.searchTableData.productStatus !== '') {
                body.filterList.push({ filterKey: 'productStatus', filterValue: this.searchTableData.productStatus})
            }
            if (page == '' || page == null || page == undefined) {
                if (body.filterList.length > 1) {
                    this.page = 1;
                    body.pageNum = 1;
                }
            }
            getStockListByOwnerCode(body,this.wmsUrl).then(({data}) => {
                if (data.returnCode == 200) {
                    this.searchInfoLoading = false;
                    this.searchInfo = data.returnData.pageInfo.list;
                    this.total = data.returnData.pageInfo.total;
                    if(this.tableDataOut.length > 0) {
                        this.selectInfo.forEach(item => {
                            this.searchInfo = this.searchInfo.filter(items => {
                                return item.filterUniqueCode != items.filterUniqueCode;
                            });
                        })
                    }
                    if (this.selectInfo.length > 0) {
                        this.selectInfo.forEach(item => {
                            this.searchInfo = this.searchInfo.filter(items => {
                                return item.filterUniqueCode != items.filterUniqueCode;
                            });
                        })
                    }
                    this.searchInfo.forEach(item => {
                        if (item.dateGen) {
                            item.dateGen = this.$utils.timestampToDate(item.dateGen)
                        }
                        if (item.dateExpire) {
                            item.dateExpire = this.$utils.timestampToDate(item.dateExpire)
                        }
                        if (item.dateInto) {
                            item.dateInto = this.$utils.timestampToDate(item.dateInto)
                        }
                        this.countryCodeList.forEach(c => {
                            if (c.code == item.country) {
                                item.country = c.codeName
                            }
                        })
                    })
                } else {
                    this.searchInfoLoading = false;
                    this.$Message.error(data.returnMsg);
                }
            });
        },
        selectCustomerInfoByDto() {
            let body = {
                filterList: [
                    {
                        filterKey: "whCode",
                        filterValue: ""
                    },
                    {
                        filterKey: 'ownerCode',
                        filterValue: this.searchOwnerCode
                    },
                    {
                        filterKey: 'supervisionStatus',
                        filterValue: '0'
                    }
                ],
                filterName: [],
                stkCodeList: [],
                pageNum: this.page,
                pageSize: this.pageSize,
                pageOptionsList: [
                    50,
                    100,
                    200
                ],
                searchKeyOrderType: null,
                sortList: [],
                searchKey: "",
                searchOwnerCode: this.searchOwnerCode,
                searchWhCode: '',
                searchSettlementCustomer: '',
                searchManageCompanyCode: '',
                outPlanOrderNum: ""
            }
            getOwnerCodeListByStock(body, this.wmsUrl).then(({data}) => {
                if (data.returnCode == 200) {
                    this.allOwner = data.returnData
                }
            })
        },
        // 判断作业类型
        isjobType() {
            if (this.$route.query.planStatus == 1) {
                this.planInformationData.applyType = 'in';
                this.applyTypeList = [
                    {
                        label: '入库',
                        value: 'in'
                    },
                    {
                        label: '人工到货',
                        value: 'move'
                    }
                ]
            } else if (this.$route.query.planStatus == 2) {
                this.applyTypeList = [
                    {
                        label: '正常出库',
                        value: 'out'
                    }
                ]
                this.planInformationData.applyType = 'out';
            }
            this.goodsBondedPropertyList = [
                {label: '一般贸易', value: 1},
                {label: '保税', value: 2}
            ],
            this.supervisionStatusList = [
                {label: '已质押', value: 1},
                {label: '未质押', value: 0}
            ],
            setTimeout(() => {
                if (this.$route.query.edit == true) {
                    this.planInformationData.cargoOwner = this.planInformationData.cargoOwnerName;
                    this.planInformationData.settlementCustomer = this.planInformationData.settlementCustomerName;
                } else {
                    this.planInformationData.cargoOwner = this.$utils.getUserInfo().entrustingPartyName;
                    this.planInformationData.settlementCustomer = this.$utils.getUserInfo().entrustingPartyName;
                }
            }, 500)
        },
        // 表格删除操作
        deleteAll() {
            this.selectTableDataList.forEach(item => {
                item.deleteFlag = 1;
            })
        },
        delectTableInfo(item, index) {
            if (this.planInformationData.applyType == 'in' || this.planInformationData.applyType == 'move') {
                if (item.id != '' && item.id != null) {
                    if (item.indexS) {
                        this.tableData[item.indexS].deleteFlag = 1;
                    } else {
                        this.tableData.forEach((itemS, index) => {
                            if (item.id == itemS.id) {
                                this.tableData[index].deleteFlag = 1;
                            }
                        })
                    }
                } else {
                    this.tableData.splice(index, 1);
                }
            } else {
                if (item.id != '' && item.id != null) {
                    if (item.indexS) {
                        this.tableDataOut[item.indexS].deleteFlag = 1;
                    } else {
                        this.tableDataOut.forEach((itemS, index) => {
                            if (item.id == itemS.id) {
                                this.tableDataOut[index].deleteFlag = 1;
                            }
                        })
                    }
                } else {
                    this.tableDataOut.splice(index, 1);
                }
            }
        },
        // 上传附件
        uploadHandler() {
            this.fileList = [];
            this.showUploadInfo = true
            this.$refs.uploadRef.clearFiles();
        },
        // 作业类型修改
        jobTypeSelectChange() {
            if (this.applyType == 'out') {
                this.tableData = [];
            } else {
                this.tableDataOut = [];
            }
        },
        // 获取码表
        getByCodeTableType() {
            getByCodeTableTypeList(this.wmsUrl).then(({data}) => {
                this.tradeCurrList = data.returnData.filter(item => {
                    return item.codeTableType == 'TRADE_CURR'
                })
                this.unitList = data.returnData.filter(item => {
                    return item.codeTableType == 'UNIT'
                })
                this.countryCodeList = data.returnData.filter(item => {
                    return item.codeTableType == 'COUNTRY_CODE'
                })
            });
        },
        // 将路由信息记录
        routingRecord() {
            this.wmsUrl = JSON.parse(this.$route.query.wmsUrl);
            this.actionUrl = this.wmsUrl + '/api/wms_file/customerUpload'
            this.uploadUrlOrder = this.wmsUrl + '/api/receive_ccis_order/importTemplate'
            if (this.$route.query.item) {
                this.editItem = JSON.parse(this.$route.query.item);
                this.planInformationData = _.cloneDeep(this.editItem);
                if (this.editItem.applyType == 'out') {
                    this.editItem.matCodeDetailList.forEach(item => {
                        if (item.deleteFlag) {
                            item.deleteFlag = 1
                        } else {
                            item.deleteFlag = 0
                        }
                    })
                    this.tableDataOut = _.cloneDeep(this.editItem.matCodeDetailList);
                } else {
                    this.tableData = _.cloneDeep(this.editItem.matCodeDetailList);
                }
                let body = {
                    "pageNum": 1,
                    "pages": 1,
                    "pageSize": 50,
                    "pageOptionsList": [
                    50,
                    100,
                    200
                    ],
                    "total": 0,
                    "sortList": [],
                    "filterList": [],
                    "selectCustomerCode": "",
                    "selectOutPlanOrderNum": "",
                    "ccisPledgePlanId": this.editItem.id, //报关申请id, 货转申请id
                    "ccisSeparationPlanId": "", //分色申请id
                    "searchOrderType": ""
                }
                console.log(1);
                getFileList(body, this.wmsUrl).then(({data}) => {
                    if (data.returnCode == 200) {
                        this.tableDataFileList = data.returnData.pageInfo.list
                        this.tableDataFileList.forEach(item => {
                            item.createdDate = this.$utils.timestampToDate(item.createdDate);
                        });
                    }
                })
            }
            this.planInformationData.whId = (this.$route.query.whId * 1);
        },
        // 复制新增
        copyAdd() {
            this.selectTableDataList.forEach(item => {
                let items = _.cloneDeep(item)
                items.id = ''
                this.tableData.push(_.cloneDeep(items));
            })
        },
        // 入库、人工倒货表格选中
        selectTableData(selection) {
            this.selectTableDataList = selection;
            this.selectTableDataListLength = _.cloneDeep(selection)
            console.log(this.selectTableDataListLength.length);
        },
        // 保存
        saveAll(status) {
          try {
            this.sLoading = true;
            let settlementCustomer = this.customerTypeList.filter(item => {
              return item.customerName == this.planInformationData.settlementCustomer
            })
            let cargoOwner = this.customerTypeList.filter(item => {
              return item.customerName == this.planInformationData.cargoOwner
            })
            if (settlementCustomer.length > 0) {
              this.planInformationData.settlementCustomerCode = settlementCustomer[0].customerCode
            } else {
              this.$Message.error('结算客户在WMS不存在')
              this.sLoading = false;
              return;
            }

            if (cargoOwner.length > 0) {
                this.planInformationData.cargoOwnerCode = cargoOwner[0].customerCode
            } else {
                this.$Message.error('货权方在WMS不存在')
                this.sLoading = false;
                return;
            }

            if (this.telTrue) {
                this.$Message.error('司机联系方式填写错误，请重新填写');
                return true
            }

            // if (this.planInformationData.cargoOwnerCode != this.$utils.getUserInfo().entrustingPartyCode && this.planInformationData.settlementCustomerCode != this.$utils.getUserInfo().entrustingPartyCode) {
            //     this.$Message.error('货权方和结算客户需一方为当前用户所在公司')
            //     return;
            // }
            if (this.planInformationData.customsStatus == 1) {
              if (this.planInformationData.applyType != 'out') {
                if (this.planInformationData.arrivalDate == null || this.planInformationData.arrivalDate == '') {
                  this.$Message.error('未报关，请填写到港日期');
                  this.sLoading = false;
                  return;
                }
              }
            } else if (this.planInformationData.customsStatus == 2) {
              if (this.planInformationData.rltEntryNo == null || this.planInformationData.rltEntryNo == '') {
                this.$Message.error('已报关，请填写关联报关单编号');
                this.sLoading = false;
                return;
              }
            }
            this.$refs['planInformationDataRule'].validate((valid) => {
              if (valid) {
                let body
                if (status == 0) {
                  body = {
                    ccisCustomerCode: this.$utils.getUserInfo().entrustingPartyCode,
                    id: '',
                    orderNum: '',
                    circulationOrderNo: "",
                    applyType: this.planInformationData.applyType,
                    businessPlanDate: '',
                    arrivalDate: this.planInformationData.arrivalDate,
                    dataSource: '6',
                    remark: this.planInformationData.remark,
                    settlementCustomer: this.planInformationData.settlementCustomerCode,
                    cargoOwner: this.planInformationData.cargoOwnerCode,
                    authenticateFlag: this.planInformationData.authenticateFlag,
                    applyStatus: this.planInformationData.applyStatus ? this.planInformationData.applyStatus : status,
                    billOfLandingNo: this.planInformationData.billOfLandingNo,
                    separationSign: this.planInformationData.separationSign ? this.planInformationData.separationSign : 0,
                    contractNo: this.planInformationData.contractNo,
                    disinfectionSign: '',
                    nucleicAcidTestFlag: 0,
                    goodsSecretKey: '',
                    entrustmentNo: '',
                    dclcusFlag: this.planInformationData.dclcusFlag ? this.planInformationData.dclcusFlag : 1,
                    customsStatus: this.planInformationData.customsStatus,
                    rltEntryNo: this.planInformationData.rltEntryNo,
                    isView: 0,
                    goodsList: this.tableData.length > 0 ? this.tableData : this.tableDataOut
                  }
                  body.goodsList.forEach(item => {
                    item['id'] = item.id ? item.id : '',
                      item['circulationOrderDetailId'] = '',
                      item['billOfLandingNo'] = this.planInformationData.billOfLandingNo,
                      item['matTypCode'] = '',
                      item['validatePeriod'] = '',
                      item['toleranceFlag'] = '',
                      item['toleranceValue'] = 0,
                      item['cargoOwner'] = this.planInformationData.cargoOwnerCode,
                      item['settlementCustomer'] = this.planInformationData.settlementCustomerCode,
                      item['newCargoOwner'] = '',
                      item['newSettlementCustomer'] = '',
                      item['indBlkRmU'] = 0;
                    item['takePhotosFlag'] = 0,
                      item['filterUniqueCode'] = item.filterUniqueCode ? item.filterUniqueCode : '',
                      item['wmsBatchNum'] = item.wmsBatchNum ? item.wmsBatchNum : '',
                      item.dateGen = item.dateGen ? new Date(moment(item.dateGen).format('YYYY-MM-DD')) : ''
                  })
                } else {
                  body = {
                    ccisCustomerCode: this.$utils.getUserInfo().entrustingPartyCode,
                    id: '',
                    orderNum: '',
                    circulationOrderNo: "",
                    applyType: this.planInformationData.applyType,
                    businessPlanDate: '',
                    arrivalDate: this.planInformationData.arrivalDate,
                    dataSource: '6',
                    remark: this.planInformationData.remark,
                    settlementCustomer: this.planInformationData.settlementCustomerCode,
                    cargoOwner: this.planInformationData.cargoOwnerCode,
                    authenticateFlag: this.planInformationData.authenticateFlag,
                    applyStatus: status,
                    billOfLandingNo: this.planInformationData.billOfLandingNo,
                    separationSign: this.planInformationData.separationSign ? this.planInformationData.separationSign : 0,
                    contractNo: this.planInformationData.contractNo,
                    disinfectionSign: '',
                    nucleicAcidTestFlag: 0,
                    goodsSecretKey: '',
                    entrustmentNo: '',
                    dclcusFlag: this.planInformationData.dclcusFlag ? this.planInformationData.dclcusFlag : 1,
                    customsStatus: this.planInformationData.customsStatus,
                    rltEntryNo: this.planInformationData.rltEntryNo,
                    isView: 0,
                    goodsList: this.tableData.length > 0 ? this.tableData : this.tableDataOut
                  }
                  body.goodsList.forEach(item => {
                    item['id'] = item.id ? item.id : '',
                      item['circulationOrderDetailId'] = '',
                      item['billOfLandingNo'] = this.planInformationData.billOfLandingNo,
                      item['matTypCode'] = '',
                      item['validatePeriod'] = '',
                      item['toleranceFlag'] = '',
                      item['toleranceValue'] = 0,
                      item['cargoOwner'] = this.planInformationData.cargoOwnerCode,
                      item['settlementCustomer'] = this.planInformationData.settlementCustomerCode,
                      item['newCargoOwner'] = '',
                      item['newSettlementCustomer'] = '',
                      item['indBlkRmU'] = 0;
                    item['takePhotosFlag'] = 0,
                      item['filterUniqueCode'] = item.filterUniqueCode ? item.filterUniqueCode : '',
                      item['wmsBatchNum'] = item.wmsBatchNum ? item.wmsBatchNum : '',
                      item.dateGen = item.dateGen ? new Date(moment(item.dateGen).format('YYYY-MM-DD')) : ''
                  })
                }
                let successC = true;
                body.goodsList.forEach(item => {
                  if (item.hscode) {
                    if (item.hscode.length < 2) {
                      this.$Message.error('商品编号请输入两位以上');
                      successC = false;
                      return;
                    }
                  }
                })

                if (successC == false) {
                  this.sLoading = false;
                  return successC;
                }

                body.goodsList.forEach(item => {
                  if (item.deleteFlag == false) {
                    item.deleteFlag = 0;
                  } else if (item.deleteFlag = true)  {
                    item.deleteFlag = 1;
                  }
                  if (item.ifCodeReading == true) {
                    item.ifCodeReading = 1;
                  } else if (item.ifCodeReading == false) {
                    item.ifCodeReading = 0;
                  }
                })

                if (this.$route.query.edit == true) {
                  body.id = this.planInformationData.id;
                  body['operator'] = this.$utils.getUserInfo().realName,
                    updatePushApplyInfoHandler(body, this.wmsUrl).then(({data}) => {
                      if (data.returnCode == 200) {
                        this.saveFile(this.editItem.id);
                        this.$Message.success('操作成功');
                        this.sLoading = false;
                        this.$router.push({
                          name: 'bondedWarehousing'
                        })
                      } else {
                        this.$Message.error(data.returnMsg);
                        this.sLoading = false;
                      }
                    })
                } else {
                  body['operator'] = this.$utils.getUserInfo().realName,
                    receivePushApplyInfoHandler(body, this.wmsUrl).then(({data}) => {
                      if (data.returnCode == 200) {
                        this.saveFile(data.returnData);
                        this.$Message.success('操作成功');
                        this.sLoading = false;
                        this.$router.push({
                          name: 'bondedWarehousing'
                        })
                      } else {
                        this.$Message.error(data.returnMsg);
                        this.sLoading = false;
                      }
                    })
                }
              } else {
                this.$Message.error('请填写必填项');
                this.sLoading = false;
              }
            })
          } catch {
            this.sLoading = false;
          }
        },
        // 输入改变
        changeInput(type, data, row) {
            switch (type) {
                case 'entryGdsSeqno':
                    row.entryGdsSeqno = !/^0{2,}/g.test(data) && !isNaN(data) && data < 100 && data.length < 3 ? data.replace(/^/g, '') : '';
                    break;
                case 'dclQty':
                    row.dclQty = !/^0{2,}/g.test(data) && !isNaN(data) && data * 1 <= row.orderQty * 1 ? data.replace(/^/g, '') : '';
                    if (row.dclTotalAmt && data != undefined && data != "" && data != 0) {
                        row.dclUprcAmt = (((row.dclTotalAmt * 1) / (row.dclQty * 1)) * 1).toFixed(5) * 1;
                    } else {
                        row.dclUprcAmt = 0;
                    }
                    break;
                case 'netWt':
                    row.netWt = !/^0{2,}/g.test(data) && !isNaN(data) ? data.replace(/^/g, '') : '';
                break;
                case 'grossWt':
                    row.grossWt = !/^0{2,}/g.test(data) && !isNaN(data) ? data.replace(/^/g, '') : '';
                break;
                case 'codeQty':
                    row.codeQty = !/^0{2,}/g.test(data) && !isNaN(data) && data * 1 <= row.orderQty * 1 ? data.replace(/^/g, '') : '';
                break;
                case 'codeWeight':
                    row.codeWeight = !/^0{2,}/g.test(data) && !isNaN(data) ? data.replace(/^/g, '') : '';
                break;
                case 'orderQty':
                    row.orderQty = !/^0{2,}/g.test(data) && !isNaN(data) && data!= 0 ? data.replace(/^/g, '') : '';
                    break;
                case 'legalDclQty':
                    row.legalDclQty = !/^0{2,}/g.test(data) && !isNaN(data) && data * 1 <= row.orderQty * 1 ? data.replace(/^/g, '') : '';
                    break;
                // case 'dclUprcAmt':
                //     row.dclUprcAmt = !/^0{2,}/g.test(data) && !isNaN(data) && data != 0 ? data.replace(/^/g, '') : '';
                //     if (row.legalDclQty && data != undefined && data != "") {
                //         row.dclTotalAmt = (((row.dclUprcAmt * 1) * (row.legalDclQty * 1)) * 1).toFixed(2);
                //     }
                //     break;
                case 'dclTotalAmt':
                    row.dclTotalAmt = !/^0{2,}/g.test(data) && !isNaN(data) && data != 0 ? data.replace(/^/g, '') : '';
                    if (row.dclQty && data != undefined && data != "" && data != 0) {
                        row.dclUprcAmt = (((row.dclTotalAmt * 1) / (row.dclQty * 1)) * 1).toFixed(5) * 1;
                    } else {
                        row.dclUprcAmt = 0;
                    }
                default:
                    break;
            }
        },
        changeBlur(type, data, row) {
            switch (type) {
                case 'containerNum':
                    testContainerNumber(data.containerNum,this.wmsUrl).then(({data}) => {
                        if (data.returnCode !== 200) {
                            if(data.returnMsg === '集装箱号必须为11位!') {
                                this.$Message.warning(data.returnMsg)
                                callback(data.returnMsg)
                            }
                        }
                    })
                    break;
                case 'netWt':
                    data.netWt = (data.netWt * 1).toFixed(3) * 1
                    break;
                case 'grossWt':
                    data.grossWt = (data.grossWt * 1).toFixed(3) * 1
                    break;
                case 'codeWeight':
                    data.codeWeight = (data.codeWeight * 1).toFixed(3) * 1
                    break;
                case 'codeQty':
                    if (data.codeQty) {
                        data.codeQty = (data.codeQty * 1).toFixed(0) * 1;
                    }
                    break;
                case 'dclQty':
                    data.dclQty = !/^0{2,}/g.test(data.dclQty) && !isNaN(data.dclQty) && data.dclQty * 1 <= data.orderQty * 1 ? data.dclQty.replace(/^/g, '') : '';
                    console.log(type, data, row);
                    if (data.dclQty) {
                        data.dclQty = (data.dclQty * 1).toFixed(3) * 1;
                    }
                    if (data.dclTotalAmt && data.dclQty != undefined && data.dclQty != "" && data.dclQty != 0) {
                        data.dclUprcAmt = (((data.dclTotalAmt * 1) / (data.dclQty * 1)) * 1).toFixed(5) * 1;
                    } else {
                        data.dclUprcAmt = 0;
                    }
                    break;
                case 'dclTotalAmt':
                    data.dclTotalAmt = ((data.dclTotalAmt * 1).toFixed(5)) * 1;
                    if (data.dclQty && data.dclTotalAmt != undefined && data.dclTotalAmt != "" && data.dclTotalAmt != 0) {
                        data.dclUprcAmt = (((data.dclTotalAmt * 1) / (data.dclQty * 1)) * 1).toFixed(5) * 1;
                    } else {
                        data.dclUprcAmt = 0;
                    }
                case 'legalDclQty':
                    data.legalDclQty = (data.legalDclQty * 1).toFixed(3) * 1;
                // case 'legalDclQty':
                //     data.legalDclQty = !/^0{2,}/g.test(data.legalDclQty) && !isNaN(data.legalDclQty) && data.legalDclQty * 1 <= data.orderQty * 1 ? data.legalDclQty.replace(/^/g, '') : '';
                //     data.legalDclQty = (data.legalDclQty * 1).toFixed(3) * 1;
                //     if (data.dclUprcAmt) {
                //         data.dclTotalAmt = (((data.dclUprcAmt * 1) * (data.legalDclQty * 1)) * 1).toFixed();
                //     }
                //     break;
                case 'orderQty':
                    // row.orderQty = !/^0{2,}/g.test(data) && !isNaN(data) && data!= 0 ? data.replace(/^/g, '') : '';
                    data.orderQty  = ((data.orderQty * 1)).toFixed(0) * 1;
                    break;
                case 'tel':
                    let isPhone =  /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
                    if (data.tel) {
                        if (!isPhone.test(data.tel) && data.tel) {
                            this.$message.error("司机联系方式填写错误，请重新填写");
                            this.telTrue = true;
                        } else {
                            this.telTrue = false;
                        }
                    } else {
                        this.telTrue = false;
                    }
                default:
                    break;
            }
        },
        // 获取结算客户
        selectByCustomerTypeList() {
            let body = {
                customerProperty: 'h'
            }
            selectByCustomerType(body, this.wmsUrl).then(({data}) => {
                this.customerTypeList = data.returnData
                this.customerTypeList.forEach(item => {
                    if (item.customerName == this.$utils.getUserInfo().entrustingPartyName) {
                        this.searchOwnerCode = item.customerCode;
                    }
                })
                this.customerTypeList.forEach(item => {
                    if (item.customerName == this.$utils.getUserInfo().entrustingPartyName) {
                        this.searchManageCompanyCode = item.companyId;
                    }
                })
            })
        }
    },
    mounted() {
        this.isjobType();
        this.routingRecord();
        this.getByCodeTableType();
        this.selectByCustomerTypeList();
        if (this.$route.query.tableData) {
            this.applyTypeList = [
                {
                    label: '正常出库',
                    value: 'out'
                }
            ]
            this.planInformationData.whId = JSON.parse(this.$route.query.menuActiveName)
            this.planInformationData.applyType = 'out'
            JSON.parse(this.$route.query.tableData).forEach(item => {
                this.tableData = [];
                item['containerNum'] = item.batchAttr07
                item['packFormat'] = item.packName
                item['orderQty'] = item.availableQty
                item['legalDclQty'] = item.availableQty
                item['ifCodeReading'] = 0
                item['businessItem'] = item.containerNum
                item['totalQty'] = (item.availableQtySum * 1).toFixed(0)
                item['deleteFlag'] = false
                if (item.dateInto) {
                    item.dateInto = this.$utils.timestampToDate(item.dateInto)
                }
                if (item.dateGen) {
                    item.dateGen = this.$utils.timestampToDate(item.dateGen)
                }
                if (item.dateExpire) {
                    item.dateExpire = this.$utils.timestampToDate(item.dateExpire)
                }
                this.tableDataOut.push(item);
            });
        }
    },
    activated() {
        this.isjobType();
    }
}
</script>

<style lang="less">
.el-table .warning-row {
    display: none;
}

.ivu-modal-content {
    position: relative;
    background-color: #fff;
    border: 0;
    border-radius: 6px;
    background-clip: padding-box;
    height: 100%;
}

.ivu-modal-body {
    padding: 16px;
    font-size: 12px;
    line-height: 1.5;
    height: 85%;
}

.el-table .el-table__cell {
    padding: 12px 0;
    min-width: 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: center;
}

.ivu-upload {
    height: 100%;
}

</style>
